﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using PefStudio.StartUp;

namespace PefStudio.Windows
{
    class AbstractToolBar : ToolBar, IToolBar, IPartImportsSatisfiedNotification
    {
        [Import(Bootstrapper.MainWindowContract, typeof(Window))]
        private Lazy<MainWindow> mainWindow { get; set; }
        protected MainWindow MainWindow
        {
            get { return mainWindow.Value; }
        }

        public string ID { get; set; }
        public double Index { get; set; }
        public string InsertRelativeToID { get; set; }
        public bool BeforeRelativeID { get; set; }

        public virtual void ConditionEvaluate()
        {
            if (Visibility == Visibility.Visible)
            {
                foreach (var item in Items)
                {
                    var iItem = item as IToolBarItem;
                    if (iItem != null) iItem.ConditionEvaluate();
                }
            }
        }

        public virtual void OnImportsSatisfied()
        {
            var v = this.Items;
        }
    }

    public class AbstractToolBarItem1 : ItemsControl, IToolBarItem
    {
        [Import(Bootstrapper.MainWindowContract, typeof(Window))]
        private Lazy<MainWindow> mainWindow { get; set; }
        protected MainWindow MainWindow
        {
            get { return mainWindow.Value; }
        }

        public string ID { get; set; }
        public double Index { get; set; }
        public string InsertRelativeToID { get; set; }
        public bool BeforeRelativeID { get; set; }

        public virtual void ConditionEvaluate() { }

        public bool HasSeparator { get; set; }
        public Separator Separator { get; set; }

        private Window _parentWindow = null;
        public Window ParentWindow
        {
            get
            {
                return _parentWindow ?? MainWindow;
            }
            set { _parentWindow = value; }
        }
    }

    public class AbstractToolBarButton : Button, IToolBarItem
    {
        public AbstractToolBarButton()
        {
            SetResourceReference(FrameworkElement.StyleProperty, ToolBar.ButtonStyleKey);
        }

        [Import(Bootstrapper.MainWindowContract, typeof(Window))]
        private Lazy<MainWindow> mainWindow { get; set; }
        protected MainWindow MainWindow
        {
            get { return mainWindow.Value; }
        }

        public string ID { get; set; }
        public double Index { get; set; }
        public string InsertRelativeToID { get; set; }
        public bool BeforeRelativeID { get; set; }

        public virtual void ConditionEvaluate() { }

        public bool HasSeparator { get; set; }
        public Separator Separator { get; set; }

        private Window _parentWindow = null;
        public Window ParentWindow
        {
            get
            {
                return _parentWindow ?? MainWindow;
            }
            set { _parentWindow = value; }
        }
    }
}
